// pages/freeTime/freeTime.js
var masterId;
var surplus=[];
var guahaoMoneyNum;
/*morningIcon: '#1296db',
  afternoonIcon:'#ECECEC',*/
Page({

  /**
   * 页面的初始数据
   */
  data: {
      Time:'上午',
      mainFont:"none",
      loading:"display"
  },
  chooseMorning:function(){
    this.checkTime(surplus, '上午');

  },
  chooseAfternoon:function(){
    this.checkTime(surplus, '下午');
  },
  checkTime:function(e,time){
      var icon1,icon2,full1,full2;
      var Time="上午";
      if(time=='上午'){
        if(e[0]>0){
          icon1='#1296db';
          icon2="#ECECEC";
          full1="";
          Time="上午";
          if(e[1]>0) full2="";
          else full2="（满）";
        }
        else{
          icon1="#ECECEC";
          full1="（满）";
          if(e[1]>0){
            icon2="#1296db";
            full2="";
            Time="下午";
          }
          else{
            icon2="#ECECEC";
            full2="（满）";
            Time="无";
          }
        }
      }
      else if(time=='下午'){
        if(e[1]>0){
          icon1="#ECECEC";
          icon2="#1296db";
          full2="";
          Time="下午";
          if(e[0]>0) full1="";
          else full1="（满）";
        }
        else{
          icon2 = "#ECECEC";
          full2 = "（满）";
          if(e[0]>0){
            icon1="#1296db";
        
            full1="";
            Time="上午";
          }
          else{
            icon1="#ECECEC";
          
            full1="（满）";
            Time="无";
          
          }
        }
      }
      this.setData(
        {
          morningIcon:icon1,
          afternoonIcon:icon2,
          full1:full1,
          full2:full2,
          Time:Time,
          loading:"none",
          mainFont:"display"
        }
      );
     

  },
  toPay:function(){
    wx.navigateTo({
      url: '../noteInput/noteInput?masterId=' + masterId + '&&Time=' + this.data.Time +"&&guahaoMoneyNum="+guahaoMoneyNum,
    })
  },
  loadData:function(masterId){
    var chooseDate=getApp().globalData.chooseDate;
    var that=this;
    wx.request({
      url: 'https://www.liuxuanlong.xyz/fenda/wx/findMasterGuahaoNum',
      data:{
        masterId:masterId,
        guahaoDate:chooseDate
      },
      success:function(res){
        console.log(res.data)
        surplus[0]=res.data.amNum;
        surplus[1]=res.data.pmNum;
        that.checkTime(surplus,'上午');
        
      },
    })
     
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      masterId=options.masterId;
      guahaoMoneyNum=options.guahaoMoneyNum;
      this.loadData(options.masterId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})